package com.xbongbong.paas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.BiConstant;
import com.xbongbong.pro.config.ProBaseConfig;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import lombok.Getter;

/**
 * 三项的后两项位置在程序里纠正
 *
 * @author 梁鲁江
 * @version v1.0
 * @date 2019/2/25 14:42
 * @since v1.0
 */
@Getter
public enum BiRelTableEnum {
    /**
     * PAAS 1XX
     * 客户
     * 合同
     * 机会
     * 联系人
     * 跟进记录
     * 回款
     * 发票
     * 供应商
     * 采购合同
     * 采购退货
     * 入库单
     * 出库单
     * 库存查询
     * 工单
     * 产品
     * 生产单
     */

    IDX_STATISTIC_PASS_DATA(101, ProBaseConfig.getEsName() + "idx_statistic_pass_data" + BiConstant.INDEX_SUFFIX, "statistic_pass_data", "", "_", XbbRefTypeEnum.PAAS.getCode()),
    /**
     * 客户作为主表（包含只有主表选了客户）
     */
    IDX_STATISTIC_CUSTOMER(201, ProBaseConfig.getEsName() + "idx_statistic_customer" + BiConstant.INDEX_SUFFIX,"customer", "enum.biRelTable.name.idx_statistic_customer", "_", XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode()),
    /**
     * 合同作为主表
     */
    IDX_STATISTIC_CONTRACT(301, ProBaseConfig.getEsName() + "idx_statistic_contract"+ BiConstant.INDEX_SUFFIX, "contract", "enum.biRelTable.name.idx_statistic_contract",  "_" , XbbRefTypeEnum.CONTRACT.getCode()),
    IDX_STATISTIC_CONTRACT_CUSTOMER(302, ProBaseConfig.getEsName() + "idx_statistic_contract_customer"+ BiConstant.INDEX_SUFFIX, "contract_customer", "enum.biRelTable.name.idx_statistic_contract_customer", XbbRefTypeEnum.CONTRACT.getCode() + "_" + XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), -1),
    IDX_STATISTIC_CONTRACT_OPP(303, ProBaseConfig.getEsName() + "idx_statistic_contract_opp"+ BiConstant.INDEX_SUFFIX,"contract_opp", "enum.biRelTable.name.idx_statistic_contract_opp", XbbRefTypeEnum.CONTRACT.getCode() + "_" + XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), -1),
    //
    IDX_STATISTIC_CONTRACT_OPP_CUSTOMER(304, ProBaseConfig.getEsName() + "idx_statistic_contract_opp_customer"+ BiConstant.INDEX_SUFFIX, "contract_opp_customer", "enum.biRelTable.name.idx_statistic_contract_opp_customer", XbbRefTypeEnum.CONTRACT.getCode() + "_" + XbbRefTypeEnum.SALES_OPPORTUNITY.getCode() + "_" + XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), -1),
    //业绩分配作为主表，但是是合同特有的，所以和合同放一起
    IDX_STATISTIC_CONTRACT_PERFORMANCE(305, ProBaseConfig.getEsName() + "idx_statistic_contract_performance"+ BiConstant.INDEX_SUFFIX, "contract_performance", "enum.biRelTable.name.idx_statistic_contract_performance", XbbRefTypeEnum.CONTRACT_PERFORMANCE.getCode() + "_" + XbbRefTypeEnum.CONTRACT.getCode() , XbbRefTypeEnum.CONTRACT_PERFORMANCE.getCode()),
    //合同 报价单
    IDX_STATISTIC_CONTRACT_QUOTATION(306, ProBaseConfig.getEsName() + "idx_statistic_contract_quotation"+ BiConstant.INDEX_SUFFIX, "contract_quotation", "enum.biRelTable.name.idx_statistic_contract_quotation", XbbRefTypeEnum.CONTRACT.getCode() + "_" + XbbRefTypeEnum.QUOTATION.getCode() , -1),
    /**
     * 机会 作为主表
     */
    IDX_STATISTIC_OPP(401, ProBaseConfig.getEsName() + "idx_statistic_opp"+ BiConstant.INDEX_SUFFIX, "opp", "enum.biRelTable.name.idx_statistic_opp", "", XbbRefTypeEnum.SALES_OPPORTUNITY.getCode()),
    IDX_STATISTIC_OPP_CUSTOMER(402, ProBaseConfig.getEsName() + "idx_statistic_opp_customer"+ BiConstant.INDEX_SUFFIX, "opp_customer", "enum.biRelTable.name.idx_statistic_opp_customer", XbbRefTypeEnum.SALES_OPPORTUNITY.getCode() + "_" + XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), -1),
    /**
     * 回款单作为主表
     */
    IDX_STATISTIC_PAYMENT(501, ProBaseConfig.getEsName() + "idx_statistic_payment"+ BiConstant.INDEX_SUFFIX,"payment", "enum.biRelTable.name.idx_statistic_payment", "_", XbbRefTypeEnum.PAYMENT_SHEET.getCode()),
    IDX_STATISTIC_PAYMENT_CONTRACT(502, ProBaseConfig.getEsName() + "idx_statistic_payment_contract"+ BiConstant.INDEX_SUFFIX, "payment_contract", "enum.biRelTable.name.idx_statistic_payment_contract", XbbRefTypeEnum.PAYMENT_SHEET.getCode()+"_"+XbbRefTypeEnum.CONTRACT.getCode(), -1),

    /**
     * 联系人作为主表
     */
    IDX_STATISTIC_CONTACT(601, ProBaseConfig.getEsName() + "idx_statistic_contact"+ BiConstant.INDEX_SUFFIX,"contact_customer", "enum.biRelTable.name.idx_statistic_contact",   "_", XbbRefTypeEnum.CONTACT.getCode()),
    IDX_STATISTIC_CONTACT_CUSTOMER(602, ProBaseConfig.getEsName() + "idx_statistic_contact_customer"+ BiConstant.INDEX_SUFFIX,"contact_customer", "enum.biRelTable.name.idx_statistic_contact_customer",  XbbRefTypeEnum.CONTACT.getCode() + "_" + XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), -1),
    /**
     * 跟进记录作为主表
     */
    IDX_STATISTIC_COMMUNICATE(701, ProBaseConfig.getEsName() + "idx_statistic_communicate"+ BiConstant.INDEX_SUFFIX,"communicate", "enum.biRelTable.name.idx_statistic_communicate",    "_", XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode()),
    IDX_STATISTIC_COMMUNICATE_CUSTOMER(702, ProBaseConfig.getEsName() + "idx_statistic_communicate_customer"+ BiConstant.INDEX_SUFFIX, "communicate_customer", "enum.biRelTable.name.idx_statistic_communicate_customer",  XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode() + "_" + XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), -1),
    /**
     * 发票作为主表
     */

    IDX_STATISTIC_INVOICE(801, ProBaseConfig.getEsName() + "idx_statistic_invoice"+ BiConstant.INDEX_SUFFIX,"invoice", "enum.biRelTable.name.idx_statistic_invoice",   "_" , XbbRefTypeEnum.INVOICE.getCode()),
    IDX_STATISTIC_INVOICE_CUSTOMER(802, ProBaseConfig.getEsName() + "idx_statistic_invoice_customer"+ BiConstant.INDEX_SUFFIX, "invoice_customer", "enum.biRelTable.name.idx_statistic_invoice_customer", XbbRefTypeEnum.INVOICE.getCode() + "_" + XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode() , -1),
    /**
     * 供应商作为主表
     */
    IDX_STATISTIC_SUPPLIER_PURCHASE(1001, ProBaseConfig.getEsName() + "idx_statistic_supplier"+ BiConstant.INDEX_SUFFIX, "supplier", "enum.biRelTable.name.idx_statistic_supplier_purchase",  "_" , XbbRefTypeEnum.SUPPLIER.getCode() ),
    /**
     * 采购合同作为主表
     */
    IDX_STATISTIC_PURCHASE(1101, ProBaseConfig.getEsName() + "idx_statistic_purchase"+ BiConstant.INDEX_SUFFIX,"purchase", "enum.biRelTable.name.idx_statistic_purchase",   "_" , XbbRefTypeEnum.PURCHASE.getCode()),
    IDX_STATISTIC_PURCHASE_SUPPLIER(1102, ProBaseConfig.getEsName() + "idx_statistic_purchase_supplier"+ BiConstant.INDEX_SUFFIX, "idx_statistic_purchase_supplier", "enum.biRelTable.name.idx_statistic_purchase_supplier", XbbRefTypeEnum.PURCHASE.getCode() + "_" + XbbRefTypeEnum.SUPPLIER.getCode(), -1),
    /**
     * 采购退货作为主表
     */
    IDX_STATISTIC_RETURNED_PURCHASE(1201, ProBaseConfig.getEsName() + "idx_statistic_returned_purchase"+ BiConstant.INDEX_SUFFIX, "returned_purchase", "enum.biRelTable.name.idx_statistic_returned_purchase",  "_" , XbbRefTypeEnum.RETURNED_PURCHASE.getCode()),
    IDX_STATISTIC_RETURNED_PURCHASE_PURCHASE(1202, ProBaseConfig.getEsName() + "idx_statistic_returned_purchase_purchase"+ BiConstant.INDEX_SUFFIX, "returned_purchase_purchase", "enum.biRelTable.name.idx_statistic_returned_purchase_purchase", XbbRefTypeEnum.RETURNED_PURCHASE.getCode() + "_" + XbbRefTypeEnum.PURCHASE.getCode(), -1),
    IDX_STATISTIC_RETURNED_PURCHASE_OUTSTOCK(1203, ProBaseConfig.getEsName() + "idx_statistic_returned_purchase_outstock"+ BiConstant.INDEX_SUFFIX, "returned_purchase_outstock", "enum.biRelTable.name.idx_statistic_returned_purchase_outstock", XbbRefTypeEnum.RETURNED_PURCHASE.getCode() + "_" + XbbRefTypeEnum.RETURNED_PURCHASE_OUTSTOCK.getCode(), -1),
    IDX_STATISTIC_RETURNED_PURCHASE_OUTSTOCK_PURCHASE(1204, ProBaseConfig.getEsName() + "idx_statistic_returned_purchase_outstock_purchase"+ BiConstant.INDEX_SUFFIX, "returned_purchase_outstock_purchase", "enum.biRelTable.name.idx_statistic_returned_purchase_outstock_purchase", XbbRefTypeEnum.RETURNED_PURCHASE.getCode() + "_" + XbbRefTypeEnum.RETURNED_PURCHASE_OUTSTOCK.getCode()+ "_" + XbbRefTypeEnum.PURCHASE.getCode(), -1),
    /**
     * 库存作为主表
     */
    IDX_STATISTIC_INVENTORY_MANAGEMENT_SUPPLIER(1301, ProBaseConfig.getEsName() + "idx_statistic_inventory_management"+ BiConstant.INDEX_SUFFIX, "inventory_management", "enum.biRelTable.name.idx_statistic_inventory_management_supplier",   "_" , XbbRefTypeEnum.INVENTORY_MANAGEMENT.getCode()),
    /**
     * 入库单作为主表
     */
    IDX_STATISTIC_INSTOCK(1401, ProBaseConfig.getEsName() + "idx_statistic_instock"+ BiConstant.INDEX_SUFFIX, "instock", "enum.biRelTable.name.idx_statistic_instock",    "_" , XbbRefTypeEnum.INSTOCK.getCode()),
//    IDX_STATISTIC_INSTOCK_CONTRACT(1402, ProBaseConfig.getEsName() + "idx_statistic_instock_contract", "instock_contract", "入库单、合同", XbbRefTypeEnum.INSTOCK.getCode()+"_"+XbbRefTypeEnum.CONTRACT.getCode(), -1),
    IDX_STATISTIC_INSTOCK_PURCHASE(1403, ProBaseConfig.getEsName() + "idx_statistic_instock_purchase"+ BiConstant.INDEX_SUFFIX, "instock_purchase", "enum.biRelTable.name.idx_statistic_instock_purchase", XbbRefTypeEnum.PURCHASE_INSTOCK.getCode()+"_"+XbbRefTypeEnum.PURCHASE.getCode(), -1),
    IDX_STATISTIC_INSTOCK_PRODUCTION_ORDER(1404, ProBaseConfig.getEsName() + "idx_statistic_instock_production_order"+ BiConstant.INDEX_SUFFIX, "instock_production_order", "enum.biRelTable.name.idx_statistic_instock_production_order", XbbRefTypeEnum.PRODUCTION_INSTOCK.getCode()+"_"+XbbRefTypeEnum.PRODUCTION_ORDER.getCode(), -1),
    IDX_STATISTIC_RETURNED_MATERIEL_INSTOCK_PRODUCTION_ORDER(1405, ProBaseConfig.getEsName() + "idx_statistic_instock_production_order"+ BiConstant.INDEX_SUFFIX, "instock_production_order", "enum.biRelTable.name.idx_statistic_returned_materiel_instock_production_order", XbbRefTypeEnum.RETURNED_MATERIEL_INSTOCK.getCode()+"_"+XbbRefTypeEnum.PRODUCTION_ORDER.getCode(), -1),
    /**
     * 出库单作为主表
     */
    IDX_STATISTIC_OUTSTOCK(1501, ProBaseConfig.getEsName() + "idx_statistic_outstock"+ BiConstant.INDEX_SUFFIX, "outstock", "enum.biRelTable.name.idx_statistic_outstock",     "_" , XbbRefTypeEnum.OUTSTOCK.getCode()),
    IDX_STATISTIC_OUTSTOCK_CONTRACT(1502, ProBaseConfig.getEsName() + "idx_statistic_outstock_contract"+ BiConstant.INDEX_SUFFIX, "outstock_contract", "enum.biRelTable.name.idx_statistic_outstock_contract", XbbRefTypeEnum.CONTRACT_OUTSTOCK.getCode()+"_"+XbbRefTypeEnum.CONTRACT.getCode(), -1),
    IDX_STATISTIC_OUTSTOCK_PRODUCTION_ORDER(1503, ProBaseConfig.getEsName() + "idx_statistic_outstock_production_order"+ BiConstant.INDEX_SUFFIX,"outstock_production_order", "enum.biRelTable.name.idx_statistic_outstock_production_order", XbbRefTypeEnum.PRODUCTION_MATERIEL_OUTSTOCK.getCode()+"_"+XbbRefTypeEnum.PRODUCTION_ORDER.getCode(), -1),
    /**
     * 工单作为主表
     */
    IDX_STATISTIC_WORKORDER_OPP(2301, ProBaseConfig.getEsName() + "idx_statistic_workorder"+ BiConstant.INDEX_SUFFIX,"workorder", "enum.biRelTable.name.idx_statistic_workorder_opp",  "_" , XbbRefTypeEnum.WORK_ORDER.getCode()),
    IDX_STATISTIC_WORKORDER_CUSTOMER(2302, ProBaseConfig.getEsName() + "idx_statistic_workorder_customer"+ BiConstant.INDEX_SUFFIX, "workorder_customer", "enum.biRelTable.name.idx_statistic_workorder_customer", XbbRefTypeEnum.WORK_ORDER.getCode() + "_" +  XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), -1),
    IDX_STATISTIC_WORKORDER_CONTRACT(2303, ProBaseConfig.getEsName() + "idx_statistic_workorder_contract"+ BiConstant.INDEX_SUFFIX, "workorder_contract", "enum.biRelTable.name.idx_statistic_workorder_contract", XbbRefTypeEnum.WORK_ORDER.getCode() + "_" +  XbbRefTypeEnum.CONTRACT.getCode(), -1),
    //
    IDX_STATISTIC_WORKORDER_CUSTOMER_CONTRACT(2304, ProBaseConfig.getEsName() + "idx_statistic_workorder_customer_contract"+ BiConstant.INDEX_SUFFIX,"workorder_customer_contract", "enum.biRelTable.name.idx_statistic_workorder_customer_contract", XbbRefTypeEnum.WORK_ORDER.getCode() + "_" + XbbRefTypeEnum.CONTRACT.getCode() + "_" +  XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), -1),
    /**
     * 生产单作为主表
     */
    IDX_STATISTIC_PRODUCTION_ORDER(2801, ProBaseConfig.getEsName() + "idx_statistic_production_order"+ BiConstant.INDEX_SUFFIX, "production_order", "enum.biRelTable.name.idx_statistic_production_order", "_" , XbbRefTypeEnum.PRODUCTION_ORDER.getCode() ),

    /**
     * 产品相关
     */
    IDX_STATISTIC_CONTRACT_PRODUCT(2401, ProBaseConfig.getEsName() + "idx_statistic_contract_product"+ BiConstant.INDEX_SUFFIX, "contract_product", "enum.biRelTable.name.idx_statistic_contract_product",XbbRefTypeEnum.CONTRACT_PRODUCT.getCode() + "_" +  XbbRefTypeEnum.CONTRACT.getCode(), XbbRefTypeEnum.CONTRACT_PRODUCT.getCode() ),
    IDX_STATISTIC_INSTOCK_PRODUCT(2402, ProBaseConfig.getEsName() + "idx_statistic_instock_product"+ BiConstant.INDEX_SUFFIX,"instock_product", "enum.biRelTable.name.idx_statistic_instock_product", XbbRefTypeEnum.INSTOCK_PRODUCT.getCode() + "_" +  XbbRefTypeEnum.INSTOCK.getCode(), XbbRefTypeEnum.INSTOCK_PRODUCT.getCode()),
    IDX_STATISTIC_SALES_OPPORTUNITY_PRODUCT(2403, ProBaseConfig.getEsName() + "idx_statistic_sales_opportunity_product"+ BiConstant.INDEX_SUFFIX, "sales_opportunity_product", "enum.biRelTable.name.idx_statistic_sales_opportunity_product", XbbRefTypeEnum.SALES_OPPORTUNITY_PRODUCT.getCode() + "_" +  XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), XbbRefTypeEnum.SALES_OPPORTUNITY_PRODUCT.getCode()),
    IDX_STATISTIC_OUTSTOCK_PRODUCT(2404, ProBaseConfig.getEsName() + "idx_statistic_outstock_product"+ BiConstant.INDEX_SUFFIX, "outstock_product", "enum.biRelTable.name.idx_statistic_outstock_product", XbbRefTypeEnum.OUTSTOCK_PRODUCT.getCode() + "_" +  XbbRefTypeEnum.OUTSTOCK.getCode(), XbbRefTypeEnum.OUTSTOCK_PRODUCT.getCode()),
    IDX_STATISTIC_PRODUCTION_ORDER_PRODUCT(2405, ProBaseConfig.getEsName() + "idx_statistic_production_order_product"+ BiConstant.INDEX_SUFFIX, "production_order_product", "enum.biRelTable.name.idx_statistic_production_order_product",XbbRefTypeEnum.PRODUCTION_ORDER_PRODUCT.getCode() + "_" +  XbbRefTypeEnum.PRODUCTION_ORDER.getCode(), XbbRefTypeEnum.PRODUCTION_ORDER_PRODUCT.getCode()),
    IDX_STATISTIC_PURCHASE_PRODUCT(2406, ProBaseConfig.getEsName() + "idx_statistic_purchase_product"+ BiConstant.INDEX_SUFFIX,"purchase_product", "enum.biRelTable.name.idx_statistic_purchase_product", XbbRefTypeEnum.PURCHASE_PRODUCT.getCode() + "_" +  XbbRefTypeEnum.PURCHASE.getCode(), XbbRefTypeEnum.PURCHASE_PRODUCT.getCode()),
    IDX_STATISTIC_RETURNED_PURCHASE_PRODUCT(2407, ProBaseConfig.getEsName() + "idx_statistic_returned_purchase_product"+ BiConstant.INDEX_SUFFIX,"returned_purchase_product", "enum.biRelTable.name.idx_statistic_returned_purchase_product",XbbRefTypeEnum.RETURNEDPURCHASE_PRODUCT.getCode() + "_" +  XbbRefTypeEnum.RETURNED_PURCHASE.getCode(), XbbRefTypeEnum.RETURNEDPURCHASE_PRODUCT.getCode()),
    IDX_STATISTIC_SUPPLIER_PRODUCT(2408, ProBaseConfig.getEsName() + "idx_statistic_supplier_product"+ BiConstant.INDEX_SUFFIX, "supplier_product", "enum.biRelTable.name.idx_statistic_supplier_product",  XbbRefTypeEnum.SUPPLIER_PRODUCT.getCode() + "_" +  XbbRefTypeEnum.SUPPLIER.getCode(), XbbRefTypeEnum.SUPPLIER_PRODUCT.getCode()),
    IDX_STATISTIC_QUOTATION_PRODUCT(2409, ProBaseConfig.getEsName() + "idx_statistic_quotation_product"+ BiConstant.INDEX_SUFFIX,"quotation_product", "enum.biRelTable.name.idx_statistic_quotation_product",  XbbRefTypeEnum.QUOTATION_PRODUCT.getCode() + "_" +  XbbRefTypeEnum.QUOTATION.getCode(), XbbRefTypeEnum.QUOTATION_PRODUCT.getCode()),
    IDX_STATISTIC_ASSEMBLE_PRODUCT(2410, ProBaseConfig.getEsName() + "idx_statistic_assemble_product"+ BiConstant.INDEX_SUFFIX, "assemble_product", "enum.biRelTable.name.idx_statistic_assemble_product",  XbbRefTypeEnum.ASSEMBLE_PRODUCT.getCode() + "_" +  XbbRefTypeEnum.ASSEMBLE.getCode(), XbbRefTypeEnum.ASSEMBLE_PRODUCT.getCode()),
    IDX_STATISTIC_ASSEMBLE_INPRODUCT(2411, ProBaseConfig.getEsName() + "idx_statistic_assemble_inproduct"+ BiConstant.INDEX_SUFFIX, "assemble_inproduct", "enum.biRelTable.name.idx_statistic_assemble_inproduct",  XbbRefTypeEnum.ASSEMBLE_INPRODUCTS.getCode() + "_" +  XbbRefTypeEnum.ASSEMBLE.getCode(), XbbRefTypeEnum.ASSEMBLE_INPRODUCTS.getCode()),
    IDX_STATISTIC_INVENTORY_PRODUCT(2412, ProBaseConfig.getEsName() + "idx_statistic_inventory_product"+ BiConstant.INDEX_SUFFIX,"inventory_product", "enum.biRelTable.name.idx_statistic_inventory_product",  XbbRefTypeEnum.INVENTORY_PRODUCT.getCode() + "_" +  XbbRefTypeEnum.INVENTORY.getCode(), XbbRefTypeEnum.INVENTORY_PRODUCT.getCode()),
    IDX_STATISTIC_TRANSFER_PRODUCT(2413, ProBaseConfig.getEsName() + "idx_statistic_transfer_product"+ BiConstant.INDEX_SUFFIX, "transfer_product", "enum.biRelTable.name.idx_statistic_transfer_product",  XbbRefTypeEnum.TRANSFER_PRODUCT.getCode() + "_" +  XbbRefTypeEnum.TRANSFER.getCode(), XbbRefTypeEnum.TRANSFER_PRODUCT.getCode()),
    IDX_STATISTIC_BOM_BILL_PRODUCT(2414, ProBaseConfig.getEsName() + "idx_statistic_bom_bill_product"+ BiConstant.INDEX_SUFFIX, "bom_bill_product", "enum.biRelTable.name.idx_statistic_bom_bill_product",  XbbRefTypeEnum.BOM_BILL_PRODUCT.getCode() + "_" +  XbbRefTypeEnum.BOM_BILL.getCode(), XbbRefTypeEnum.BOM_BILL_PRODUCT.getCode()),

    /**
     * 报价单
     * 合同订单、报价单
     * 报价单、机会
     * 报价单、客户
     */
    IDX_STATISTIC_QUOTATION(4700, ProBaseConfig.getEsName() + "idx_statistic_quotation"+ BiConstant.INDEX_SUFFIX,"quotation", "enum.biRelTable.name.idx_statistic_quotation",   "_"  , XbbRefTypeEnum.QUOTATION.getCode()),
    IDX_STATISTIC_QUOTATION_OPP(4701, ProBaseConfig.getEsName() + "idx_statistic_quotation_opp"+ BiConstant.INDEX_SUFFIX, "quotation_opp", "enum.biRelTable.name.idx_statistic_quotation_opp",   XbbRefTypeEnum.QUOTATION.getCode()+"_"+XbbRefTypeEnum.SALES_OPPORTUNITY.getCode()  , -1),
    IDX_STATISTIC_QUOTATION_CUSTOMER(4702, ProBaseConfig.getEsName() + "idx_statistic_quotation_customer"+ BiConstant.INDEX_SUFFIX, "quotation_customer", "enum.biRelTable.name.idx_statistic_quotation_customer",   XbbRefTypeEnum.QUOTATION.getCode()+"_"+XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode()   , -1),

    /**
     * 市场活动
     */
    IDX_STATISTIC_MARKET_ACTIVITY(8100, ProBaseConfig.getEsName() + "idx_statistic_market_activity"+ BiConstant.INDEX_SUFFIX,"market_activity", "enum.biRelTable.name.idx_statistic_market_activity",   "_"  , XbbRefTypeEnum.MARKET_ACTIVITY.getCode()),

    /**
     * 销售线索
     */
    IDX_STATISTIC_CLUE(8000, ProBaseConfig.getEsName() + "idx_statistic_clue"+ BiConstant.INDEX_SUFFIX,"clue", "enum.biRelTable.name.idx_statistic_clue",   "_"  , XbbRefTypeEnum.CLUE.getCode()),


    IDX_STATISTIC_DYNAMIC_DATA(10000, ProBaseConfig.getEsName() + "idx_statistic_dynamic"+ BiConstant.INDEX_SUFFIX, "dynamic_data", "",  "_", XbbRefTypeEnum.DYNAMIC_DATA.getCode()),
    /**
     * 不在自定义报表关系定义中的索引(自定义表单-关联数据内设置)
     */
    IDX_STATISTIC_DEFAULT_DATA(10001, ProBaseConfig.getEsName() + "idx_statistic_default_data"+ BiConstant.INDEX_SUFFIX,"default_data", "",  "_",  XbbRefTypeEnum.DEFAULT_DATA.getCode()),
    ;

    /**
     * 编号标示
     */
    private Integer code;
    /**
     * index
     */
    private String index;
    /**
     * type
     */
    private String type;
    /**
     * 名称
     */
    private String name;
    /**
     * 联合code
     */
    private String mutiCode;
    /**
     * 映射XbbRefTypeEnum
     */
    private Integer refCode;

    BiRelTableEnum(Integer code, String index, String type, String name, String mutiCode, Integer refCode) {
        this.code = code;
        this.index = index;
        this.type = type;
        this.name = name;
        this.mutiCode = mutiCode;
        this.refCode = refCode;
    }

    /**
     * 根据mutiCode获取枚举
     * @param mutiCode 联合code
     * @return
     */
    public static BiRelTableEnum getByMutiCode(String mutiCode) {
        for (BiRelTableEnum cacheCode : values()) {
            if (mutiCode.equals(cacheCode.getMutiCode())) {
                return cacheCode;
            }
        }
        return null;
    }

    /**
     * 根据refCode获取枚举
     * @param refCode 关联code
     * @return
     * @see com.xbongbong.saas.enums.XbbRefTypeEnum
     */
    public static BiRelTableEnum getByRefCode(Integer refCode) {
        for (BiRelTableEnum cacheCode : values()) {
            if (refCode.equals(cacheCode.getRefCode())) {
                return cacheCode;
            }
        }
        return null;
    }

    public static BiRelTableEnum getIndex(String alias) {
        for (BiRelTableEnum cacheCode : values()) {
            if (cacheCode.getIndex().equals(alias)) {
                return cacheCode;
            }
        }
        return null;
    }
    /**
     * 根据refCode获取枚举
     * @param  code
     * @return
     */
    public static BiRelTableEnum getByCode(Integer code) {
        for (BiRelTableEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return null;
    }
/*    public static boolean inHere(String  index) {
        for (BiRelTableEnum cacheCode : values()) {
            if (Objects.equals(index,cacheCode.getIndex())) {
                return true;
            }
        }
        return false;
    }*/
    private static Set<String> indexSet = new HashSet<>(BiRelTableEnum.values().length);
    static {
        for (BiRelTableEnum cacheCode : BiRelTableEnum.values()) {
            indexSet.add(cacheCode.getIndex());
        }
    }
    public static boolean inHere(String  index) {
        return indexSet.contains(index);
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public static void main(String[] args) {
        for (BiRelTableEnum value : BiRelTableEnum.values()) {
            String index = value.index;
            index = index.replaceAll("null","");
            index = "test_" + index;
            System.out.println("PUT  "+ index  + "_v1" + "/_alias/" + index  );
        }
    }
}
